<template>
  <button
    class="common-button"
    :class="[type, size, { 'is-plain': plain, 'is-active': active }]"
    @click="handleClick"
  >
    <slot></slot>
  </button>
</template>

<script>
export default {
  name: 'CommonButton',
  props: {
    type: {
      type: String,
      default: 'default',
      validator: value => [
        'default',
        'primary',
        'success',
        'warning',
        'danger'
      ].includes(value)
    },
    size: {
      type: String,
      default: 'medium',
      validator: value => ['small', 'medium', 'large'].includes(value)
    },
    plain: {
      type: Boolean,
      default: false
    },
    active: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleClick(event) {
      this.$emit('click', event)
    }
  }
}
</script>

<style lang="scss" scoped>
.common-button {
  display: inline-block;
  padding: 8px 15px;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;

  &:hover {
    opacity: 0.8;
  }

  &.primary {
    background: #409eff;
    border-color: #409eff;
    color: #fff;
  }

  &.success {
    background: #67c23a;
    border-color: #67c23a;
    color: #fff;
  }

  &.warning {
    background: #e6a23c;
    border-color: #e6a23c;
    color: #fff;
  }

  &.danger {
    background: #f56c6c;
    border-color: #f56c6c;
    color: #fff;
  }

  &.is-plain {
    background: #fff;
    &.primary {
      color: #409eff;
    }
    &.success {
      color: #67c23a;
    }
    &.warning {
      color: #e6a23c;
    }
    &.danger {
      color: #f56c6c;
    }
  }

  &.is-active {
    color: #ff5722;
    font-weight: 600;
    font-size: 16px;
  }

  &.small {
    padding: 6px 12px;
    font-size: 12px;
  }

  &.large {
    padding: 12px 20px;
    font-size: 16px;
  }
}
</style>